#include <utils/category.h>


namespace AccountManagerUtils {
	
//! Default constructor
Category::Category() : name_(""), description_("") {}

//! Copy constructor
Category::Category(const Category& rhs) : name_(rhs.name_), description_(rhs.description_) {}

//! Constructor from a name
Category::Category(const String& name) : name_(name), description_("") {}

//! Constructor from a name and a description
Category::Category(const String& name, const String& description) :
	name_(name), description_(description) {}

//! Destructor
Category::~Category() {}

//! Copy constructor
Category& Category::operator=(const Category& rhs) {
	if ( &rhs != this ) {
		name_ = rhs.name_;
		description_ = rhs.description_;
	}
	return *this;
}

//! Comparison operator
/*!
 *  This operator only compares the name, but ignores the description
 */
bool Category::operator==(const Category& rhs) const {
	return ( name_ == rhs.name_ );
}

//! Difference operator
/*!
 *  This operator only compares the name, but ignores the description
 */
bool Category::operator!=(const Category& rhs) const {
	return ( name_ != rhs.name_ );
}

//! Accessor to the name of the category (read-write)
String& Category::name() {
	return name_;
}

//! Accessor to the name of the category (read only)
const String& Category::name() const {
	return name_;
}

//! Accessor to the description of the category (read-write)
String& Category::description() {
	return description_;
}

//! Accessor to the description of the category (read only)
const String& Category::description() const {
	return description_;
}

//===========================================================

//! Initialize the category lib instance
CategoryLib* CategoryLib::instance_ = NULL;

//! Find a category with given name, if any
const Category* CategoryLib::find_category(const String& name) {
	QSet<Category>::iterator it = instance()->categories_.find(name);
	if ( it == instance()->categories_.end() ) {
		return NULL;
	}
	return &(*it);
}

//! Get the list of categories
const Set<Category>& CategoryLib::categories() {
	return instance()->categories_;
}

//! Destructor
CategoryLib::~CategoryLib() {}

//! Constructor
CategoryLib::CategoryLib() {}

//! Find or create the instance of CategoryLib
CategoryLib* CategoryLib::instance() {
	if ( instance_ == NULL ) {
		instance_ = new CategoryLib();
	}
	return instance_;
}

} // namespace AccountManagerUtils

